/**
 * Project litesql++
 */


#include "sqlite_table.h"

/**
 * SQLiteTable implementation
 */


SQLiteTable::SQLiteTable(): table_name_(""), records_pos_(0) { }

SQLiteTable::~SQLiteTable() { }


/**
 * @return const string
 */
const string& SQLiteTable::table_name() const {
    return table_name_;
}

/**
 * @param table_name
 * @return void
 */
void SQLiteTable::set_table_name(const string& table_name) {
    table_name_ = table_name;
}

/**
 * @param column_name
 * @param flag
 * @return void
 */
void SQLiteTable::AddColumn(const string& column_name, const string& flag) {
    columns_.push_back(column_name + " " + flag + ", ");
}

/**
 * @return const string
 */
const string SQLiteTable::ColumnsAsSQLCreateString() const {
    string columns;
    vector<string>::const_iterator it;

    for (it = columns_.cbegin(); it != columns_.cend(); ++it) {
        columns += *it;
    }
    columns = columns.substr(0, columns.length() - 2);

    return columns;
}

/**
 * @return const shared_ptr<SQLiteRecord>
 */
const shared_ptr<SQLiteRecord> SQLiteTable::GetNextRecord() {
    if (records_pos_ < records_.size()) {
        return records_[records_pos_++];
    }
    return nullptr;
}

void SQLiteTable::AddRecord(shared_ptr<SQLiteRecord> record) {
    records_.push_back(record);
}


/**
 * @return void
 */
void SQLiteTable::ResetRecords() {
    records_.clear();
    records_pos_ = 0;
}

/**
 * @return const int
 */
const int SQLiteTable::GetRecordCount() {
    return records_.size();
}


